<?php defined('IN_ADMIN') or exit('Access Denied!'); ?>
<?php
  @list($dtime1, $dtime2, $dtime3, $dtime4) = preg_split('/[\s-]+/', $data['delivery_time']);
  $data['delivery_time'] = array($dtime1, $dtime2, $dtime3, $dtime4);
?>

<div class="subnav">
  <div class="content-menu ib-a blue line-x"> <a><em>商户管理</em></a> <span>|</span>
    <?php if($method == 'create'){ ?>
    <a class="on"><em>添加新商户</em></a>
    <?php }else{ ?>
    <a class="on"><em>编辑商户</em></a>
    <?php } ?>
  </div>
</div>
<form action="/admin/shop/save/<?=isset($data['shop_id'])?intval($data['shop_id']):'';?>" method="post" id="myform">
  <input type="hidden" name="method" value="<?=$method;?>" />
  <div class="pad-10">
    <div class="col-tab">
      <ul class="tabBut cu-li" id="tab_setting">
        <li id="tab_setting_1" class="on">基本信息</li>
        <li id="tab_setting_2">联系信息</li>
        <li id="tab_setting_3">SEO 优化</li>
        <li id="tab_setting_4">风格设置</li>
        <li id="tab_setting_5">其他设置</li>
      </ul>
      <!-- 1.基本信息 -->
      <div id="div_setting_1" class="contentList pad-10">
        <table width="100%" class="table_form">
          <?php if($method == 'modify'){ ?>
          <tr>
            <th width="120" height="24">商户ID</th>
            <td class="y-bg"><?=i($data['shop_id']);?></td>
          </tr>
          <?php }else{ ?>
          <tr>
            <th width="120" height="24">商户类型</th>
            <td class="y-bg">
                <select name="shop_type" id="shop_type">
                    <?=View::options(array(1=>'外卖', 2=>'酒店'), array_get_int($_GET, 'shop_type'));?>
                </select>
            </td>
          </tr>
          <?php }?>
          <tr>
            <th width="120">商户名称</th>
            <td class="y-bg"><input type="text" class="input-text" name="name" id="name" size="50" value="<?=h($data['name']);?>"/></td>
          </tr>
          <tr>
            <th width="120">别 名</th>
            <td class="y-bg"><input type="text" class="input-text" name="alias_name" id="alias_name" size="50" value="<?=h($data['alias_name']);?>"/>
              &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">缩略语或者更完整的称谓</font></td>
          </tr>
          <tr>
            <th width="120">营业时间</th>
            <td class="y-bg"><input type="text" class="input-text" name="worktime" id="worktime" size="50" value="<?=h($data['worktime']);?>"/>
              &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">如："周一至周五8:00-17:00"</font></td>
          </tr>
          <tr>
            <th width="120">预约电话</th>
            <td class="y-bg"><input type="text" class="input-text" name="telphone" id="telphone" size="50" value="<?=trim(h($data['telphone']),'/');?>" />
              &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">多个电话可用“/”分割</font></td>
          </tr>
          <tr>
            <th width="120">简介（广告语）</th>
            <td class="y-bg"><textarea name="topic" cols="47" rows="3" id="topic"><?=h($data['topic']);?></textarea></td>
          </tr>
        </table>
      </div>
      <!-- 2.联系方式 -->
      <div id="div_setting_2" class="contentList pad-10 hidden">
        <table width="100%" class="table_form">
          <tr>
            <th width="120">联系人</th>
            <td class="y-bg"><input type="text" class="input-text" name="contact" id="contact" size="50" value="<?=h($data['contact']);?>"/></td>
          </tr>
          <tr>
            <th width="120">手 机</th>
            <td class="y-bg"><input type="text" class="input-text" name="mobile" id="mobile" size="50" value="<?=h($data['mobile']);?>"/></td>
          </tr>
          <tr>
            <th width="120" rowspan="2">商家地址</th>
            <td class="y-bg"><select id="zone_id" name="zone_id" rel="<?=i($data['zone_id']);?>">
                <option value="0" selected>请选择...</option>
              </select>
              <select id="subzone_id" name="subzone_id" rel="<?=i($data['subzone_id']);?>">
                <option value="0" selected>请选择...</option>
              </select></td>
          </tr>
          <tr>
            <td class="y-bg"><input type="text" name="address" id="address" size="50" class="input-text" value="<?=h($data['address']);?>" /></td>
          </tr>
          <tr>
            <th width="120">交通信息</th>
            <td class="y-bg"><textarea name="traffic" id="traffic" cols="47" rows="3"><?=h($data['traffic']);?></textarea>
              &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">如乘车路线等</font></td>
          </tr>
          <tr>
            <th width="120" rowspan="2">地图标点</th>
            <td class="y-bg"> 经度：
              <input type="text" name="longitude" id="longitude" value="<?=h($data['longitude']);?>" />
            </td>
          </tr>
          <tr>
            <td class="y-bg"> 纬度：
              <input type="text" name="latitude" id="latitude" value="<?=h($data['latitude']);?>" />
              <span class="tips"><a href="http://dev.baidu.com/wiki/static/map/API/tool/getPoint/" target="_blank">百度地图标点拾取</a></span></td>
          </tr>
        </table>
      </div>
      <!-- 3.SEO 优化 -->
      <div id="div_setting_3" class="contentList pad-10 hidden">
        <table width="100%" class="table_form">
          <tr>
            <th width="120">SEO 标题</th>
            <td class="y-bg"><input type="text" name="seo_title" id="seo_title" size="50" class="input-text" value="<?=h($data['seo_title']);?>" /></td>
          </tr>
          <tr>
            <th width="120">SEO 关键字</th>
            <td class="y-bg"><input type="text" name="seo_keywords" id="seo_keywords" size="50" class="input-text" value="<?=h($data['seo_keywords']);?>" /></td>
          </tr>
          <tr>
            <th width="120">SEO 描述</th>
            <td class="y-bg"><textarea name="seo_description" id="seo_description" cols="47" rows="3"><?=h($data['seo_description']);?></textarea></td>
          </tr>
        </table>
      </div>
      <!-- 4.模板风格 -->
      <div id="div_setting_4" class="contentList pad-10 hidden">
        <table width="100%" class="table_form">
          <tr>
            <th width="100">封面图像</th>
            <td class="y-bg"><div class="create-picture">
              <img id="picshow-0" src="<?=empty($data['picture']) ? STATIC_URL.'img/common/upload.gif' : UPLOAD_URL.$data['picture'] ;?>" height="110" />
              </div>
              <input type="hidden" id="picture-0" name="picture" value="<?=h($data['picture']);?>" />
              <a href="#" id="upfile-0">[上传照片]</a><span id="pictip-0"></span></td>
          </tr>
          <tr>
            <th width="120">模板图片</th>
            <td class="y-bg"><input type="text" name="header_image" id="header_image" size="50" class="input-text" value="<?=h($data['header_image']);?>" />
              &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">具体可咨询客服</font></td>
          </tr>
          <tr>
            <th width="120">模板颜色</th>
            <td class="y-bg"><input type="text" name="header_color" id="header_color" size="50" class="input-text" value="<?=h($data['header_color']);?>" />
              &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">具体可咨询客服</font></td>
          </tr>
        </table>
      </div>
      <!-- 5.其他设置(管理员界面)/400电话 -->
      <div id="div_setting_5" class="contentList pad-10 hidden">
      <?php if($isadmin){ ?>
        <table width="100%" class="table_form">
          <tr>
            <th width="120">商户状态</th>
            <td class="y-bg">
              <input name="status" value="0" type="radio"<?php if($data['status'] == 0) echo ' checked'; ?>>&nbsp;关闭页面<br />
              <input name="status" value="1" type="radio"<?php if($data['status'] == 1) echo ' checked'; ?>>&nbsp;仅提供电话订餐<br />
              <input name="status" value="2" type="radio"<?php if($data['status'] == 2) echo ' checked'; ?>>&nbsp;允许网上订餐<br />
              <input name="status" value="3" type="radio"<?php if($data['status'] == 3) echo ' checked'; ?>>&nbsp;允许在线支付<br />
            </td>
          </tr>
          <tr>
            <th>400分机</th>
            <td class="y-bg"><u>400-0411-569 转</u> <input type="text" class="input-text" name="call_number" id="call_number" size="16" value="<?=i($data['call_number']);?>"/>
                  &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">0为关闭</font></td>
          </tr>
          <tr>
            <th>短信号码</th>
            <td class="y-bg"><input type="text" class="input-text" name="sms_number" id="sms_number" size="30" value="<?=h($data['sms_number']);?>"/>
                  &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">0为关闭</font></td>
          </tr>
          <tr>
            <th>浏览量</th>
            <td class="y-bg"><input type="text" class="input-text" name="views" id="views" size="30" value="<?=i($data['views']);?>"/></td>
          </tr>
          <tr>
            <th>喜 欢</th>
            <td class="y-bg"><input type="text" class="input-text" name="likes" id="likes" size="30" value="<?=i($data['likes']);?>"/></td>
          </tr>
          <tr>
            <th>分 享</th>
            <td class="y-bg"><input type="text" class="input-text" name="shares" id="shares" size="30" value="<?=i($data['shares']);?>"/></td>
          </tr>
          <tr>
            <th>星 级</th>
            <td class="y-bg"><input type="text" class="input-text" name="star" id="star" size="30" value="<?=i($data['star']);?>"/></td>
          </tr>
          <tr>
            <th>用户ID</th>
            <td class="y-bg"><input type="text" class="input-text" name="admin_uid" id="admin_uid" size="30" value="<?=i($data['admin_uid']);?>"/></td>
          </tr>
          <tr>
            <th>备注信息</th>
            <td class="y-bg"><textarea name="memo" id="memo" cols="47" rows="3"><?=h($data['memo']);?></textarea></td>
          </tr>
        </table>
      <?php }else{ ?>
        <table width="100%" class="table_form">
          <tr>
            <th width="120">400分机号码</th>
            <td class="y-bg"><?php if($data['call_number']){ ?>
              <p>恭喜您，你已开通400分机号码！</p>
              <div style="margin:24px 0;padding:10px;background:green;font-size:16px;font-weight:bold;color:#fff;width:300px;text-align:center"> 400-0411-569 转 <font color="red">
                <?=i($data['call_number']);?>
                </font> </div>
              <?php }else{?>
              <p style="color:red">您尚未开通400分机号码！</p>
              <?php } ?>
              <p>如有问题请联系客服！</p></td>
          </tr>
        </table>
      <?php } ?>
      </div>

      <div class="bk15"></div>
      <input name="dosubmit" type="submit" value="提交" class="button">
    </div>
  </div>
</form>
<script type="text/javascript">
$(document).ready(function(){
    tabs('#tab_setting', 'setting');

    $.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
    $("#name").formValidator({onshow:"请输入商户名称",onfocus:"请输入商户名称"}).inputValidator({min:1,onerror:"商户名称没有填写"});
    $("#zone_id,#subzone_id").formValidator({onshow:"请选择区域/板块",onfocus:"请选择区域/板"}).functionValidator({
        fun:function(){return ($("#subzone_id").val() >0 && $("#zone_id").val() > 0);},
        onerror:"区域/板块没有选择"
    });
    $("#address").formValidator({onshow:"请输入商户地址",onfocus:"请输入商户地址"}).inputValidator({min:1,onerror:"商户地址没有填写"});
    $("#topic").formValidator({onshow:"请输入商户简介（广告语）",onfocus:"请用一句话描述，200字以内"}).inputValidator({max:200,onerror:"简介内容至多200字"});

    //剪裁图片
    var img_w = 200;
    var img_h = 140;
    $("#pictip-0").text("（尺寸为" +img_w+ "x" +img_h+ "）");
    $("#upfile-0").click(function(){
        window.top.art.dialog(
            {id:"tailor", iframe:"/admin/attach/tailor?width=" +img_w+ "&height=" +img_h+ "", title:"图片剪裁", width:750, height:530, lock:true}
        );
    });
});
</script>

<?php
  function shop_time_option($from, $to, $time){
    $time = isset($time) ? $time : '';
    for($i=$from*2;$i<=$to*2;$i++){
      $tmp = date("H:i", $i*1800 + 3600*16);
      $sel = ($time == $tmp) ? ' selected' : '';
      echo '<option value="' .$tmp. '"' .$sel. '>' .$tmp. '</option>';
    }
  }
?>
